package com.mostromas.ess.product.controller;

import com.mostromas.ess.entities.ProductSeason;
import com.mostromas.ess.entities.ProductYear;
import com.mostromas.ess.product.service.IProductSeasonService;
import com.mostromas.ess.product.service.IProductYearService;
import com.mostromas.ess.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 商品季节表-前端控制器
 */
@Api(value = "商品季节管理接口",description = "季节管理接口，提供季节的增、删、改、查")
@RestController //所有方法都会返回json字符串进行相应
@RequestMapping("/season")
public class ProductSeasonController {

    @Autowired
    private IProductSeasonService productSeasonService;

    @PreAuthorize(("hasAuthority('season:search')"))
    @ApiOperation("查询商品季节详情接口")
    @ApiImplicitParam(name = "id",value = "季节ID",required = true)
    @GetMapping("/{id}") //请求路径：/product/season/{id}
    public Result view(@PathVariable("id") String id){
        ProductSeason productSeason = productSeasonService.getById(id);
        return Result.ok(productSeason);
    }

    @PreAuthorize(("hasAuthority('season:edit')"))
    @ApiOperation("修改商品季节信息接口")
    @PutMapping //put方式调用接口：/product/season
    public Result update(@RequestBody ProductSeason productSeason){
        productSeasonService.updateById(productSeason);
        return Result.ok();
    }

    @PreAuthorize(("hasAuthority('season:add')"))
    @ApiOperation("新增商品季节信息接口")
    @PostMapping //post方式调用接口：/product/season
    public Result save(@RequestBody ProductSeason productSeason){
        productSeasonService.save(productSeason);
        return Result.ok();
    }

    @PreAuthorize(("hasAuthority('season:delete')"))
    @ApiOperation("删除商品季节信息接口")
    @ApiImplicitParam(name = "id",value = "季节ID",required = true)
    @DeleteMapping("/{id}") //delete方式调用接口：/product/season/{id}
    public Result delete(@PathVariable("id") String id){
        productSeasonService.removeById(id);
        return Result.ok();
    }

    @PreAuthorize(("hasAuthority('season:search')"))
    @ApiOperation("获取所有的商品季节信息接口")
    @GetMapping("/list") //请求路径：/product/season/list
    public Result list(){
        return productSeasonService.selectAll();
    }
}
